#ifndef _ECON_H_
#define _ECON_H_

#define ECON_VERSION "STEYcon version 1.0 patchlevel 0 [07/07/2002]"

// Produces a bigger log than needed during play
#define ECON_BIG_LOG		1

#define ECON_PARENT             -1

#define MONITOR_ROOM		1333

#define BANK_DATA               1181
#define COMMOD_DATA             1111
#define FACTORY_DATA            1179
#define MARKET_DATA             1178
#define MINE_DATA               1180
#define UPG_DATA                1118
#define WARE_DATA               1182
#define ECON_DATA		1114

#define WARE_SPACE		500000
#define MINE_SPACE		100000
#define FACTORY_SPACE		200000
#define MARKET_SPACE		200000

#define MONITOR_ROOM_ATTR	"MONITOR"

#define WARE_SPACE_ATTR		"WAR_SPACE"
#define MINE_SPACE_ATTR		"MIN_SPACE"
#define FACTORY_SPACE_ATTR	"FAC_SPACE"
#define MARKET_SPACE_ATTR	"MAR_SPACE"

#define BANK_DATA_ATTR          "BAN_DATA"
#define COMMOD_DATA_ATTR        "COM_DATA"
#define FACTORY_DATA_ATTR       "FAC_DATA"
#define MARKET_DATA_ATTR        "MAR_DATA"
#define MINE_DATA_ATTR          "MIN_DATA"
#define UPG_DATA_ATTR           "UPG_DATA"
#define WARE_DATA_ATTR          "WAR_DATA"
#define ECON_DATA_ATTR		"ECO_DATA"

#define AGRI_WORKERS_ATTR	"AGRI_WORKERS"
#define HOURLY_REQ_ATTR		"HOURLY_REQ"
#define FOOD_STORAGE_ATTR	"FOOD_STORAGE"
#define RESEARCH_ATTR		"RESEARCH_LEVEL"
#define POPULATION_ATTR		"POPULATION"
#define CURRENCIES_ATTR		"CURRENCIES"
#define EXCH_RATE_ATTR		"EXCH_RATE"
#define TAX_ATTR		"TAX_RATE"
#define TAXES_ATTR		"TAXES"
#define SLAVES_ATTR		"SLAVES"
#define RENT_ATTR		"RENT"

// Triggers
#define RENTER_BROKE		"TR_RENTER_BROKE"

#define MORALE_ATTR		"MORALE"

#define ECON_OK			"\x1B[32m-\x1B[0m"
#define ECON_ERR		"\x1B[31m-\x1B[0m"

#define MAX_STORAGE             128

/* 
ownerdb|operatordb|upglevel|usedtons|destination|open/closed|prodrate|miningcmod|workers|wages|rent|(cmod1-qty1~cmod2-qty2...) 
*/

struct  commod_t {
        char    name[25];
        double  qty;
};

struct	accounts_t {
	dbref	holder;
	double	has;
	double	owe;
	double	rent;	
};

struct  storage_t {
        dbref   owner;
        dbref   oper;
        int     upglevel;
        int     commods;
        double  usedtons;
        char    destination[25];
        char    open[25];
        double  prodrate;
        char    prodcommod[25];
        double  workers;
        double  wages;
        double  rent;
        double	remaining_space;
        struct commod_t commod[MAX_STORAGE];
};

struct  bank_t {
        dbref   owner;
        dbref   oper;
        int     upglevel;
        char	empty1[25];
        double  money;
        char    open[25];
        char    empty2[25];
        double  interest;        
        double  workers;
        double  wages;
        double  rent;        
        int	accounts;
        struct accounts_t account[MAX_STORAGE];        
};
	
struct	commods_t {
	int	cost;
	int	tech;
	double	prodrate;
	char	prodbld[25];
	int	reqs;
	struct commod_t req[MAX_STORAGE];
};

/* From econ.c */
extern int split_building(char *instr, char *zone, char *building);
extern int bext(dbref data, char *instr, int pos, char *outstr);
extern int do_move_commod (dbref *zone, char *source, char *dest, int *qty);
extern int get_food_source(dbref zone, char *source, char *dest);
extern int uncrank_req(char *instr, char *commod, double qty);	
extern int deposit_account (dbref zone, char *building, char *account, double amount);
extern int withdraw_account (dbref zone, char *building, char *account, double amount);
extern int check_account (dbref zone, char *building, char *account, char *amount);
extern int do_add_commod (dbref zone, char *dest, char	*commod, char *qty);
extern int do_rem_commod (dbref zone, char *dest, char	*commod, char *qty);
extern int validate_commod(char *commod);
extern int return_commod(dbref enactor, char *commod, char *retstr);
extern int get_commod(char *commod, struct commods_t *clist);
extern int uncrank_bank (dbref zone, char *struc, struct bank_t *bd);
extern int crank_bank (dbref zone, char *struc, struct bank_t *bd);
extern int counts(const char *ord, char srchstr);
extern int get_store_str (dbref zone, char *obj, char *str);
extern int set_store_str (dbref zone, char *obj, char *str);
extern int rem_zeros(struct storage_t *clist);
extern double get_agri_workers(dbref zone);
extern double get_morale(dbref zone);
extern double has_in_store (dbref zone, char *dest, char *commod);
extern double parse_double (char *str);
extern double get_total_space(char *obj, int upglevel);
extern struct storage_t calc_tons (struct storage_t ts);
extern void crank (struct storage_t *sto, char *tn);
extern void uncrank (char *instr, struct storage_t *ts);
extern void has_commod(dbref zone, char *dest, char *commod, char *qty);
extern void get_tax(dbref zone, char *tax);
extern void add_taxes(dbref zone, double tax);
extern void exch (char *from, char *qty);
extern void do_reposess (dbref zone, char *dest);

/* From econ_variables.c */
extern dbref econ_parent;
extern dbref monitor_room;
extern dbref bank_data;
extern dbref commod_data;
extern dbref factory_data;
extern dbref market_data;
extern dbref mine_data;
extern dbref upg_data;
extern dbref ware_data;
extern dbref econ_data;
extern int factory_space;
extern int mine_space;
extern int ware_space;
extern int market_space;
extern const char *econ_errors[];
extern int do_get_referances (dbref executor, dbref ep);

/* From econ_prod.c */
extern int do_trigger_food(dbref enactor, dbref zone);
extern int fac_trig(dbref player, dbref thing, char const *pattern __attribute__ ((__unused__)), ATTR *atr, void *args);
extern int min_trig(dbref player, dbref thing, char const *pattern __attribute__ ((__unused__)), ATTR *atr, void *args);
extern int do_ftrigger(dbref enactor);
extern int do_mtrigger(dbref enactor);
// extern int tr_wages(dbref player, dbref thing, char const *pattern __attribute__ ((__unused__)), ATTR *atr, void *args);

#endif /* _ECON_H_ */
